/*
 * @(#)DmsObjectHomeFolderDAObject.java
 *
 * Copyright (c) 2003 DCIVision Ltd
 * All rights reserved.
 *
 * This software is the confidential and proprietary information of DCIVision
 * Ltd ("Confidential Information").  You shall not disclose such Confidential
 * Information and shall use it only in accordance with the terms of the license
 * agreement you entered into with DCIVision Ltd.
 */
package com.dcivision.dms.dao;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Timestamp;
import java.util.ArrayList;
import java.util.List;
import java.util.Vector;

import com.dcivision.dms.bean.DmsObjectHomeFolder;
import com.dcivision.framework.ApplicationException;
import com.dcivision.framework.ErrorConstant;
import com.dcivision.framework.GlobalConstant;
import com.dcivision.framework.SessionContainer;
import com.dcivision.framework.SystemParameterConstant;
import com.dcivision.framework.SystemParameterFactory;
import com.dcivision.framework.TextUtility;
import com.dcivision.framework.UserInfoFactory;
import com.dcivision.framework.Utility;
import com.dcivision.framework.bean.AbstractBaseObject;
import com.dcivision.framework.dao.AbstractDAObject;
import com.dcivision.framework.web.AbstractSearchForm;
;

/**
  DmsObjectHomeFolderDAObject.java

  This class is the data access bean for table "DMS_GROUP_ROLE_FOLDER".

  @author          Jenny Li
  @company         DCIVision Limited
  @creation date   23/11/2004
  @version         $Revision: 1.10 $
*/

public class DmsObjectHomeFolderDAObject extends AbstractDAObject {

  public static final String REVISION = "$Revision: 1.10 $";

  public static final String TABLE_NAME = "DMS_OBJECT_HOME_FOLDER";

  public DmsObjectHomeFolderDAObject(SessionContainer sessionContainer, Connection dbConn) {
    super(sessionContainer, dbConn);
  }

  protected void initDBSetting() {
    this.baseTableName = TABLE_NAME;
    this.vecDBColumn.add("ID");
    this.vecDBColumn.add("DOCUMENT_ID");
    this.vecDBColumn.add("MEMBER_ID");
    this.vecDBColumn.add("MEMBER_TYPE");
    this.vecDBColumn.add("ITEM_STATUS");
    this.vecDBColumn.add("RECORD_STATUS");
    this.vecDBColumn.add("UPDATE_COUNT");
    this.vecDBColumn.add("CREATOR_ID");
    this.vecDBColumn.add("CREATE_DATE");
    this.vecDBColumn.add("UPDATER_ID");
    this.vecDBColumn.add("UPDATE_DATE");
  }

  protected synchronized AbstractBaseObject getByID(Integer id) throws ApplicationException {
    PreparedStatement preStat = null;
    ResultSet rs = null;
    StringBuffer sqlStat = new StringBuffer();

    synchronized(dbConn) {
      try {
        sqlStat.append("SELECT A.ID, A.DOCUMENT_ID, A.MEMBER_ID, A.MEMBER_TYPE, A.ITEM_STATUS, A.RECORD_STATUS, A.UPDATE_COUNT, A.CREATOR_ID, A.CREATE_DATE, A.UPDATER_ID, A.UPDATE_DATE ");
        sqlStat.append("FROM   DMS_OBJECT_HOME_FOLDER A ");
        sqlStat.append("WHERE  A.ID = ? AND A.RECORD_STATUS = ? ");
        preStat = dbConn.prepareStatement(sqlStat.toString(), ResultSet.TYPE_SCROLL_INSENSITIVE, ResultSet.CONCUR_READ_ONLY);
        this.setPrepareStatement(preStat, 1, id);
        this.setPrepareStatement(preStat, 2, GlobalConstant.RECORD_STATUS_ACTIVE);
        rs = preStat.executeQuery();
        if (rs.next()) {
          DmsObjectHomeFolder tmpDmsObjectHomeFolder = new DmsObjectHomeFolder();
          tmpDmsObjectHomeFolder.setID(getResultSetInteger(rs, "ID"));
          tmpDmsObjectHomeFolder.setDocumentID(getResultSetInteger(rs, "DOCUMENT_ID"));
          tmpDmsObjectHomeFolder.setMemberID(getResultSetInteger(rs, "MEMBER_ID"));
          tmpDmsObjectHomeFolder.setMemberType(getResultSetString(rs, "MEMBER_TYPE"));
          tmpDmsObjectHomeFolder.setItemStatus(getResultSetString(rs, "ITEM_STATUS"));
          tmpDmsObjectHomeFolder.setRecordStatus(getResultSetString(rs, "RECORD_STATUS"));
          tmpDmsObjectHomeFolder.setUpdateCount(getResultSetInteger(rs, "UPDATE_COUNT"));
          tmpDmsObjectHomeFolder.setCreatorID(getResultSetInteger(rs, "CREATOR_ID"));
          tmpDmsObjectHomeFolder.setCreateDate(getResultSetTimestamp(rs, "CREATE_DATE"));
          tmpDmsObjectHomeFolder.setUpdaterID(getResultSetInteger(rs, "UPDATER_ID"));
          tmpDmsObjectHomeFolder.setUpdateDate(getResultSetTimestamp(rs, "UPDATE_DATE"));
          tmpDmsObjectHomeFolder.setCreatorName(UserInfoFactory.getUserFullName(tmpDmsObjectHomeFolder.getCreatorID()));
          tmpDmsObjectHomeFolder.setUpdaterName(UserInfoFactory.getUserFullName(tmpDmsObjectHomeFolder.getUpdaterID()));
          return(tmpDmsObjectHomeFolder);
        } else {
          throw new ApplicationException(ErrorConstant.DB_RECORD_NOT_FOUND_ERROR);
        }
      } catch (ApplicationException appEx) {
        throw appEx;
      } catch (SQLException sqle) {
        log.error(sqle, sqle);
        throw new ApplicationException(ErrorConstant.DB_GENERAL_ERROR, sqle, sqle.toString());
      } catch (Exception e) {
        log.error(e, e);
        throw new ApplicationException(ErrorConstant.DB_SELECT_ERROR, e);
      } finally {
        try { rs.close(); } catch (Exception ignore) {} finally { rs = null; }
        try { preStat.close(); } catch (Exception ignore) {} finally { preStat = null; }
      }
    }
  }

  protected synchronized List getList(AbstractSearchForm searchForm) throws ApplicationException {
    PreparedStatement preStat = null;
    PreparedStatement preStatCnt = null;
    ResultSet rs = null;
    ResultSet rsCnt = null;
    StringBuffer sqlStat = new StringBuffer();
    StringBuffer sqlStatCnt = new StringBuffer();
    List result = new ArrayList();
    int totalNumOfRecord = 0;
    int rowLoopCnt = 0;
    int startOffset = TextUtility.parseInteger(searchForm.getCurStartRowNo());
    int pageSize = TextUtility.parseInteger(searchForm.getPageOffset());

    synchronized(dbConn) {
      try {
        sqlStat.append("SELECT A.ID, A.DOCUMENT_ID, A.MEMBER_ID, A.MEMBER_TYPE, A.ITEM_STATUS, A.RECORD_STATUS, A.UPDATE_COUNT, A.CREATOR_ID, A.CREATE_DATE, A.UPDATER_ID, A.UPDATE_DATE ");
        sqlStat.append("FROM   DMS_OBJECT_HOME_FOLDER A ");
        sqlStat.append("WHERE  A.RECORD_STATUS = ? ");

        // Form the WHERE clause for filtering.
        if (searchForm.isSearchable()) {
          String searchField = getSearchColumn(searchForm.getBasicSearchField());
          sqlStat.append("AND  " + searchField + " " + searchForm.getBasicSearchType() + " ? ");
        }

        //format the sql for any 'LIKE' statement contained
        sqlStat = this.getFormattedSQL(sqlStat.toString());

        // Form the ORDER clause for sorting.
        if (searchForm.isSortable()) {
          String sortAttribute = searchForm.getSortAttribute();
          if (sortAttribute.indexOf(".") < 0) {
            sortAttribute = "A." + sortAttribute;
          }
          sqlStat.append("ORDER BY " + sortAttribute + " " + searchForm.getSortOrder());
        }

        // Get total number of record return.
        sqlStatCnt = this.getSelectCountSQL(sqlStat);
        preStatCnt = dbConn.prepareStatement(sqlStatCnt.toString(), ResultSet.TYPE_SCROLL_INSENSITIVE, ResultSet.CONCUR_READ_ONLY);
        this.setPrepareStatement(preStatCnt, 1, GlobalConstant.RECORD_STATUS_ACTIVE);
        if (searchForm.isSearchable()) {
          String searchKeyword = this.getFormattedKeyword(searchForm.getBasicSearchKeyword(), searchForm.getBasicSearchType());
          this.setPrepareStatement(preStatCnt, 2, searchKeyword);
        }
        rsCnt = preStatCnt.executeQuery();
        if (rsCnt.next()) {
          totalNumOfRecord = rsCnt.getInt(1);
        }
        try { rsCnt.close(); } catch (Exception ignore) {} finally { rsCnt = null; }
        try { preStatCnt.close(); } catch (Exception ignore) {} finally { preStatCnt = null; }

        // Retrieve the result in row basis.
        sqlStat = this.getSelectListSQL(sqlStat, startOffset, pageSize);
        preStat = dbConn.prepareStatement(sqlStat.toString(), ResultSet.TYPE_SCROLL_INSENSITIVE, ResultSet.CONCUR_READ_ONLY);
        this.setPrepareStatement(preStat, 1, GlobalConstant.RECORD_STATUS_ACTIVE);
        if (searchForm.isSearchable()) {
          String searchKeyword = this.getFormattedKeyword(searchForm.getBasicSearchKeyword(), searchForm.getBasicSearchType());
          this.setPrepareStatement(preStat, 2, searchKeyword);
        }
        rs = preStat.executeQuery();

        this.positionCursor(rs, startOffset, pageSize);

        while (rs.next() && rowLoopCnt<pageSize) {
          DmsObjectHomeFolder tmpDmsObjectHomeFolder = new DmsObjectHomeFolder();
          tmpDmsObjectHomeFolder.setID(getResultSetInteger(rs, "ID"));
          tmpDmsObjectHomeFolder.setDocumentID(getResultSetInteger(rs, "DOCUMENT_ID"));
          tmpDmsObjectHomeFolder.setMemberID(getResultSetInteger(rs, "MEMBER_ID"));
          tmpDmsObjectHomeFolder.setMemberType(getResultSetString(rs, "MEMBER_TYPE"));
          tmpDmsObjectHomeFolder.setItemStatus(getResultSetString(rs, "ITEM_STATUS"));
          tmpDmsObjectHomeFolder.setRecordStatus(getResultSetString(rs, "RECORD_STATUS"));
          tmpDmsObjectHomeFolder.setUpdateCount(getResultSetInteger(rs, "UPDATE_COUNT"));
          tmpDmsObjectHomeFolder.setCreatorID(getResultSetInteger(rs, "CREATOR_ID"));
          tmpDmsObjectHomeFolder.setCreateDate(getResultSetTimestamp(rs, "CREATE_DATE"));
          tmpDmsObjectHomeFolder.setUpdaterID(getResultSetInteger(rs, "UPDATER_ID"));
          tmpDmsObjectHomeFolder.setUpdateDate(getResultSetTimestamp(rs, "UPDATE_DATE"));
          tmpDmsObjectHomeFolder.setCreatorName(UserInfoFactory.getUserFullName(tmpDmsObjectHomeFolder.getCreatorID()));
          tmpDmsObjectHomeFolder.setUpdaterName(UserInfoFactory.getUserFullName(tmpDmsObjectHomeFolder.getUpdaterID()));
          tmpDmsObjectHomeFolder.setRecordCount(totalNumOfRecord);
          tmpDmsObjectHomeFolder.setRowNum(startOffset++);
          ++rowLoopCnt;
          result.add(tmpDmsObjectHomeFolder);
        }
        return(result);
      } catch (ApplicationException appEx) {
        throw appEx;
      } catch (SQLException sqle) {
        log.error(sqle, sqle);
        throw new ApplicationException(ErrorConstant.DB_GENERAL_ERROR, sqle, sqle.toString());
      } catch (Exception e) {
        log.error(e, e);
        throw new ApplicationException(ErrorConstant.DB_SELECT_ERROR, e);
      } finally {
        try { rs.close(); } catch (Exception ignore) {} finally { rs = null; }
        try { preStat.close(); } catch (Exception ignore) {} finally { preStat = null; }
        try { rsCnt.close(); } catch (Exception ignore) {} finally { rsCnt = null; }
        try { preStatCnt.close(); } catch (Exception ignore) {} finally { preStatCnt = null; }
      }
    }
  }

  protected synchronized List getList() throws ApplicationException {
    PreparedStatement preStat = null;
    ResultSet rs = null;
    StringBuffer sqlStat = new StringBuffer();
    List result = new ArrayList();

    synchronized(dbConn) {
      try {
        sqlStat.append("SELECT A.ID, A.DOCUMENT_ID, A.MEMBER_ID, A.MEMBER_TYPE, A.ITEM_STATUS, A.RECORD_STATUS, A.UPDATE_COUNT, A.CREATOR_ID, A.CREATE_DATE, A.UPDATER_ID, A.UPDATE_DATE ");
        sqlStat.append("FROM   DMS_OBJECT_HOME_FOLDER A ");
        sqlStat.append("WHERE  A.RECORD_STATUS = ? ");
        preStat = dbConn.prepareStatement(sqlStat.toString(), ResultSet.TYPE_SCROLL_INSENSITIVE, ResultSet.CONCUR_READ_ONLY);
        this.setPrepareStatement(preStat, 1, GlobalConstant.RECORD_STATUS_ACTIVE);
        rs = preStat.executeQuery();
        while (rs.next()) {
          DmsObjectHomeFolder tmpDmsObjectHomeFolder = new DmsObjectHomeFolder();
          tmpDmsObjectHomeFolder.setID(getResultSetInteger(rs, "ID"));
          tmpDmsObjectHomeFolder.setDocumentID(getResultSetInteger(rs, "DOCUMENT_ID"));
          tmpDmsObjectHomeFolder.setMemberID(getResultSetInteger(rs, "MEMBER_ID"));
          tmpDmsObjectHomeFolder.setMemberType(getResultSetString(rs, "MEMBER_TYPE"));
          tmpDmsObjectHomeFolder.setItemStatus(getResultSetString(rs, "ITEM_STATUS"));
          tmpDmsObjectHomeFolder.setRecordStatus(getResultSetString(rs, "RECORD_STATUS"));
          tmpDmsObjectHomeFolder.setUpdateCount(getResultSetInteger(rs, "UPDATE_COUNT"));
          tmpDmsObjectHomeFolder.setCreatorID(getResultSetInteger(rs, "CREATOR_ID"));
          tmpDmsObjectHomeFolder.setCreateDate(getResultSetTimestamp(rs, "CREATE_DATE"));
          tmpDmsObjectHomeFolder.setUpdaterID(getResultSetInteger(rs, "UPDATER_ID"));
          tmpDmsObjectHomeFolder.setUpdateDate(getResultSetTimestamp(rs, "UPDATE_DATE"));
          tmpDmsObjectHomeFolder.setCreatorName(UserInfoFactory.getUserFullName(tmpDmsObjectHomeFolder.getCreatorID()));
          tmpDmsObjectHomeFolder.setUpdaterName(UserInfoFactory.getUserFullName(tmpDmsObjectHomeFolder.getUpdaterID()));
          result.add(tmpDmsObjectHomeFolder);
        }
        return(result);
      } catch (ApplicationException appEx) {
        throw appEx;
      } catch (SQLException sqle) {
        log.error(sqle, sqle);
        throw new ApplicationException(ErrorConstant.DB_GENERAL_ERROR, sqle, sqle.toString());
      } catch (Exception e) {
        log.error(e, e);
        throw new ApplicationException(ErrorConstant.DB_SELECT_ERROR, e);
      } finally {
        try { rs.close(); } catch (Exception ignore) {} finally { rs = null; }
        try { preStat.close(); } catch (Exception ignore) {} finally { preStat = null; }
      }
    }
  }

  protected void validateInsert(AbstractBaseObject obj) throws ApplicationException {
  }

  protected void validateUpdate(AbstractBaseObject obj) throws ApplicationException {
  }

  protected void validateDelete(AbstractBaseObject obj) throws ApplicationException {
  }

  protected synchronized AbstractBaseObject insert(AbstractBaseObject obj) throws ApplicationException {
    PreparedStatement preStat = null;
    StringBuffer sqlStat = new StringBuffer();
    DmsObjectHomeFolder tmpDmsObjectHomeFolder = (DmsObjectHomeFolder)((DmsObjectHomeFolder)obj).clone();

    synchronized(dbConn) {
      try {
        Integer nextID = getNextPrimaryID();
        Timestamp currTime = Utility.getCurrentTimestamp();
        sqlStat.append("INSERT ");
        sqlStat.append("INTO   DMS_OBJECT_HOME_FOLDER(ID, DOCUMENT_ID, MEMBER_ID, MEMBER_TYPE, ITEM_STATUS, RECORD_STATUS, UPDATE_COUNT, CREATOR_ID, CREATE_DATE, UPDATER_ID, UPDATE_DATE) ");
        sqlStat.append("VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?) ");
        preStat = dbConn.prepareStatement(sqlStat.toString(), ResultSet.TYPE_SCROLL_INSENSITIVE, ResultSet.CONCUR_READ_ONLY);
        setPrepareStatement(preStat, 1, nextID);
        setPrepareStatement(preStat, 2, tmpDmsObjectHomeFolder.getDocumentID());
        setPrepareStatement(preStat, 3, tmpDmsObjectHomeFolder.getMemberID());
        setPrepareStatement(preStat, 4, tmpDmsObjectHomeFolder.getMemberType());
        setPrepareStatement(preStat, 5, tmpDmsObjectHomeFolder.getItemStatus());
        setPrepareStatement(preStat, 6, GlobalConstant.RECORD_STATUS_ACTIVE);
        setPrepareStatement(preStat, 7, new Integer(0));
        setPrepareStatement(preStat, 8, sessionContainer.getUserRecordID());
        setPrepareStatement(preStat, 9, currTime);
        setPrepareStatement(preStat, 10, sessionContainer.getUserRecordID());
        setPrepareStatement(preStat, 11, currTime);
        preStat.executeUpdate();
        tmpDmsObjectHomeFolder.setID(nextID);
        tmpDmsObjectHomeFolder.setCreatorID(sessionContainer.getUserRecordID());
        tmpDmsObjectHomeFolder.setCreateDate(currTime);
        tmpDmsObjectHomeFolder.setUpdaterID(sessionContainer.getUserRecordID());
        tmpDmsObjectHomeFolder.setUpdateDate(currTime);
        tmpDmsObjectHomeFolder.setUpdateCount(new Integer(0));
        tmpDmsObjectHomeFolder.setCreatorName(UserInfoFactory.getUserFullName(tmpDmsObjectHomeFolder.getCreatorID()));
        tmpDmsObjectHomeFolder.setUpdaterName(UserInfoFactory.getUserFullName(tmpDmsObjectHomeFolder.getUpdaterID()));
        return(tmpDmsObjectHomeFolder);
      } catch (ApplicationException appEx) {
        throw appEx;
      } catch (SQLException sqle) {
        log.error(sqle, sqle);
        throw new ApplicationException(ErrorConstant.DB_GENERAL_ERROR, sqle, sqle.toString());
      } catch (Exception e) {
        log.error(e, e);
        throw new ApplicationException(ErrorConstant.DB_INSERT_ERROR, e);
      } finally {
        try { preStat.close(); } catch (Exception ignore) {} finally { preStat = null; }
      }
    }
  }

  protected synchronized AbstractBaseObject update(AbstractBaseObject obj) throws ApplicationException {
    PreparedStatement preStat = null;
    StringBuffer sqlStat = new StringBuffer();
    DmsObjectHomeFolder tmpDmsObjectHomeFolder = (DmsObjectHomeFolder)((DmsObjectHomeFolder)obj).clone();

    synchronized(dbConn) {
      try {
        int updateCnt = 0;
        Timestamp currTime = Utility.getCurrentTimestamp();
        sqlStat.append("UPDATE DMS_OBJECT_HOME_FOLDER ");
        sqlStat.append("SET  DOCUMENT_ID=?, MEMBER_ID=?, MEMBER_TYPE=?, ITEM_STATUS=?, UPDATE_COUNT=?, UPDATER_ID=?, UPDATE_DATE=? ");
        sqlStat.append("WHERE  ID=? AND UPDATE_COUNT=? ");
        preStat = dbConn.prepareStatement(sqlStat.toString(), ResultSet.TYPE_SCROLL_INSENSITIVE, ResultSet.CONCUR_READ_ONLY);
        setPrepareStatement(preStat, 1, tmpDmsObjectHomeFolder.getDocumentID());
        setPrepareStatement(preStat, 2, tmpDmsObjectHomeFolder.getMemberID());
        setPrepareStatement(preStat, 3, tmpDmsObjectHomeFolder.getMemberType());
        setPrepareStatement(preStat, 4, tmpDmsObjectHomeFolder.getItemStatus());
        setPrepareStatement(preStat, 5, new Integer(tmpDmsObjectHomeFolder.getUpdateCount().intValue() + 1));
        setPrepareStatement(preStat, 6, sessionContainer.getUserRecordID());
        setPrepareStatement(preStat, 7, currTime);
        setPrepareStatement(preStat, 8, tmpDmsObjectHomeFolder.getID());
        setPrepareStatement(preStat, 9, tmpDmsObjectHomeFolder.getUpdateCount());
        updateCnt = preStat.executeUpdate();
        if (updateCnt == 0) {
          throw new ApplicationException(ErrorConstant.DB_CONCURRENT_ERROR);
        } else {
          tmpDmsObjectHomeFolder.setUpdaterID(sessionContainer.getUserRecordID());
          tmpDmsObjectHomeFolder.setUpdateDate(currTime);
          tmpDmsObjectHomeFolder.setUpdateCount(new Integer(tmpDmsObjectHomeFolder.getUpdateCount().intValue() + 1));
          tmpDmsObjectHomeFolder.setCreatorName(UserInfoFactory.getUserFullName(tmpDmsObjectHomeFolder.getCreatorID()));
          tmpDmsObjectHomeFolder.setUpdaterName(UserInfoFactory.getUserFullName(tmpDmsObjectHomeFolder.getUpdaterID()));
          return(tmpDmsObjectHomeFolder);
        }
      } catch (ApplicationException appEx) {
        throw appEx;
      } catch (SQLException sqle) {
        log.error(sqle, sqle);
        throw new ApplicationException(ErrorConstant.DB_GENERAL_ERROR, sqle, sqle.toString());
      } catch (Exception e) {
        log.error(e, e);
        throw new ApplicationException(ErrorConstant.DB_UPDATE_ERROR, e);
      } finally {
        try { preStat.close(); } catch (Exception ignore) {} finally { preStat = null; }
      }
    }
  }

  protected synchronized AbstractBaseObject delete(AbstractBaseObject obj) throws ApplicationException {
    PreparedStatement preStat = null;
    StringBuffer sqlStat = new StringBuffer();
    DmsObjectHomeFolder tmpDmsObjectHomeFolder = (DmsObjectHomeFolder)((DmsObjectHomeFolder)obj).clone();

    synchronized(dbConn) {
      try {
        int updateCnt = 0;
        sqlStat.append("DELETE ");
        sqlStat.append("FROM   DMS_OBJECT_HOME_FOLDER ");
        sqlStat.append("WHERE  ID=? AND UPDATE_COUNT=? ");
        preStat = dbConn.prepareStatement(sqlStat.toString(), ResultSet.TYPE_SCROLL_INSENSITIVE, ResultSet.CONCUR_READ_ONLY);
        setPrepareStatement(preStat, 1, tmpDmsObjectHomeFolder.getID());
        setPrepareStatement(preStat, 2, tmpDmsObjectHomeFolder.getUpdateCount());
        updateCnt = preStat.executeUpdate();
        if (updateCnt == 0) {
          throw new ApplicationException(ErrorConstant.DB_CONCURRENT_ERROR);
        } else {
          return(tmpDmsObjectHomeFolder);
        }
      } catch (ApplicationException appEx) {
        throw appEx;
      } catch (SQLException sqle) {
        log.error(sqle, sqle);
        throw new ApplicationException(ErrorConstant.DB_GENERAL_ERROR, sqle, sqle.toString());
      } catch (Exception e) {
        log.error(e, e);
        throw new ApplicationException(ErrorConstant.DB_DELETE_ERROR, e);
      } finally {
        try { preStat.close(); } catch (Exception ignore) {} finally { preStat = null; }
      }
    }
  }

  protected synchronized void auditTrail(String opMode, AbstractBaseObject obj) throws ApplicationException {
    Vector oldValues = new Vector();
    Vector newValues = new Vector();
    DmsObjectHomeFolder tmpDmsObjectHomeFolder = (DmsObjectHomeFolder)this.oldValue;

    if (tmpDmsObjectHomeFolder != null) {
      oldValues.add(toAuditTrailValue(tmpDmsObjectHomeFolder.getID()));
      oldValues.add(toAuditTrailValue(tmpDmsObjectHomeFolder.getDocumentID()));
      oldValues.add(toAuditTrailValue(tmpDmsObjectHomeFolder.getMemberID()));
      oldValues.add(toAuditTrailValue(tmpDmsObjectHomeFolder.getMemberType()));
      oldValues.add(toAuditTrailValue(tmpDmsObjectHomeFolder.getItemStatus()));
      oldValues.add(toAuditTrailValue(tmpDmsObjectHomeFolder.getRecordStatus()));
      oldValues.add(toAuditTrailValue(tmpDmsObjectHomeFolder.getUpdateCount()));
      oldValues.add(toAuditTrailValue(tmpDmsObjectHomeFolder.getCreatorID()));
      oldValues.add(toAuditTrailValue(tmpDmsObjectHomeFolder.getCreateDate()));
      oldValues.add(toAuditTrailValue(tmpDmsObjectHomeFolder.getUpdaterID()));
      oldValues.add(toAuditTrailValue(tmpDmsObjectHomeFolder.getUpdateDate()));
    }

    tmpDmsObjectHomeFolder = (DmsObjectHomeFolder)obj;
    if (tmpDmsObjectHomeFolder != null) {
      newValues.add(toAuditTrailValue(tmpDmsObjectHomeFolder.getID()));
      newValues.add(toAuditTrailValue(tmpDmsObjectHomeFolder.getDocumentID()));
      newValues.add(toAuditTrailValue(tmpDmsObjectHomeFolder.getMemberID()));
      newValues.add(toAuditTrailValue(tmpDmsObjectHomeFolder.getMemberType()));
      newValues.add(toAuditTrailValue(tmpDmsObjectHomeFolder.getItemStatus()));
      newValues.add(toAuditTrailValue(tmpDmsObjectHomeFolder.getRecordStatus()));
      newValues.add(toAuditTrailValue(tmpDmsObjectHomeFolder.getUpdateCount()));
      newValues.add(toAuditTrailValue(tmpDmsObjectHomeFolder.getCreatorID()));
      newValues.add(toAuditTrailValue(tmpDmsObjectHomeFolder.getCreateDate()));
      newValues.add(toAuditTrailValue(tmpDmsObjectHomeFolder.getUpdaterID()));
      newValues.add(toAuditTrailValue(tmpDmsObjectHomeFolder.getUpdateDate()));
    }

    auditTrailBase(opMode, oldValues, newValues);
  }

  /***********************************************************************
   * DON'T Modify the codes above unless you know what you are doing!!!  *
   * Put your own functions beblow.                                      *
   * For FINDER methods, the function name should be in the notation:    *
   *   public Object getObjectBy<Criteria>()                             *
   *   - e.g. public Object getObjectByCode()                            *
   *   public List getListBy<Criteria>()                                 *
   *   - e.g. public List getListByUserID()                              *
   * For OPERATION methods, the function name should be in the notation: *
   *   public void <Operation>ObjectBy<Criteria>()                       *
   *   - e.g. public void deleteObjectByCode()                           *
   *   public void <Operation>ListBy<Criteria>()                         *
   *   - e.g. public void deleteListByUserID()                           *
   ***********************************************************************/
  
/**
 * Gets list of dmsHomeobject with group type and role type
 * 
 * @param searchForm abstractSearch Form 
 * @return list of dmsHomeObjects
 * @throws ApplicationException
 */
  public synchronized List getGroupRoleList(AbstractSearchForm searchForm) throws ApplicationException {
    PreparedStatement preStat = null;
    PreparedStatement preStatCnt = null;
    ResultSet rs = null;
    ResultSet rsCnt = null;
    StringBuffer sqlStat = new StringBuffer();
    StringBuffer sqlStatCnt = new StringBuffer();
    List result = new ArrayList();
    int totalNumOfRecord = 0;
    int rowLoopCnt = 0;
    int startOffset = TextUtility.parseInteger(searchForm.getCurStartRowNo());
    int pageSize = TextUtility.parseInteger(searchForm.getPageOffset());
    
    synchronized(dbConn) {
      try {
        sqlStat.append("SELECT A.ID, A.DOCUMENT_ID, A.MEMBER_ID, A.MEMBER_TYPE, A.ITEM_STATUS, A.RECORD_STATUS, A.UPDATE_COUNT, A.CREATOR_ID, A.CREATE_DATE, A.UPDATER_ID, A.UPDATE_DATE ");
        sqlStat.append("FROM   DMS_OBJECT_HOME_FOLDER A ");
        sqlStat.append("WHERE  A.RECORD_STATUS = ? ");
        sqlStat.append("AND (A.MEMBER_TYPE = ? OR A.MEMBER_TYPE = ? ) ");

        // Form the ORDER clause for sorting.
        if (searchForm.isSortable()) {
          String sortAttribute = searchForm.getSortAttribute();
          if (sortAttribute.indexOf(".") < 0) {
            sortAttribute = "A." + sortAttribute;
          }
          sqlStat.append("ORDER BY " + sortAttribute + " " + searchForm.getSortOrder());
        }
        
        //Get total number of record return.
        sqlStatCnt = this.getSelectCountSQL(sqlStat);
        preStatCnt = dbConn.prepareStatement(sqlStatCnt.toString(), ResultSet.TYPE_SCROLL_INSENSITIVE, ResultSet.CONCUR_READ_ONLY);
        this.setPrepareStatement(preStatCnt, 1, GlobalConstant.RECORD_STATUS_ACTIVE);
        this.setPrepareStatement(preStatCnt, 2, DmsObjectHomeFolder.MEMBER_TYPE_GROUP);
        this.setPrepareStatement(preStatCnt, 3, DmsObjectHomeFolder.MEMBER_TYPE_ROLE);   
        rsCnt = preStatCnt.executeQuery();
        if (rsCnt.next()) {
          totalNumOfRecord = rsCnt.getInt(1);
        }
        try { rsCnt.close(); } catch (Exception ignore) {} finally { rsCnt = null; }
        try { preStatCnt.close(); } catch (Exception ignore) {} finally { preStatCnt = null; }
        
        // Retrieve the result in row basis.
        sqlStat = this.getSelectListSQL(sqlStat, startOffset, pageSize);
        preStat = dbConn.prepareStatement(sqlStat.toString(), ResultSet.TYPE_SCROLL_INSENSITIVE, ResultSet.CONCUR_READ_ONLY);
        this.setPrepareStatement(preStat, 1, GlobalConstant.RECORD_STATUS_ACTIVE);
        this.setPrepareStatement(preStat, 2, DmsObjectHomeFolder.MEMBER_TYPE_GROUP);
        this.setPrepareStatement(preStat, 3, DmsObjectHomeFolder.MEMBER_TYPE_ROLE);  
        rs = preStat.executeQuery();
        while (rs.next()) {
          DmsObjectHomeFolder tmpDmsObjectHomeFolder = new DmsObjectHomeFolder();
          tmpDmsObjectHomeFolder.setID(getResultSetInteger(rs, "ID"));
          tmpDmsObjectHomeFolder.setDocumentID(getResultSetInteger(rs, "DOCUMENT_ID"));
          tmpDmsObjectHomeFolder.setMemberID(getResultSetInteger(rs, "MEMBER_ID"));
          tmpDmsObjectHomeFolder.setMemberType(getResultSetString(rs, "MEMBER_TYPE"));
          tmpDmsObjectHomeFolder.setItemStatus(getResultSetString(rs, "ITEM_STATUS"));
          tmpDmsObjectHomeFolder.setRecordStatus(getResultSetString(rs, "RECORD_STATUS"));
          tmpDmsObjectHomeFolder.setUpdateCount(getResultSetInteger(rs, "UPDATE_COUNT"));
          tmpDmsObjectHomeFolder.setCreatorID(getResultSetInteger(rs, "CREATOR_ID"));
          tmpDmsObjectHomeFolder.setCreateDate(getResultSetTimestamp(rs, "CREATE_DATE"));
          tmpDmsObjectHomeFolder.setUpdaterID(getResultSetInteger(rs, "UPDATER_ID"));
          tmpDmsObjectHomeFolder.setUpdateDate(getResultSetTimestamp(rs, "UPDATE_DATE"));
          tmpDmsObjectHomeFolder.setCreatorName(UserInfoFactory.getUserFullName(tmpDmsObjectHomeFolder.getCreatorID()));
          tmpDmsObjectHomeFolder.setUpdaterName(UserInfoFactory.getUserFullName(tmpDmsObjectHomeFolder.getUpdaterID()));
          tmpDmsObjectHomeFolder.setRecordCount(totalNumOfRecord);
          tmpDmsObjectHomeFolder.setRowNum(startOffset++);
          ++rowLoopCnt;
          result.add(tmpDmsObjectHomeFolder);
        }
        return(result);
      } catch (ApplicationException appEx) {
        throw appEx;
      } catch (SQLException sqle) {
        log.error(sqle, sqle);
        throw new ApplicationException(ErrorConstant.DB_GENERAL_ERROR, sqle, sqle.toString());
      } catch (Exception e) {
        log.error(e, e);
        throw new ApplicationException(ErrorConstant.DB_SELECT_ERROR, e);
      } finally {
        try { rs.close(); } catch (Exception ignore) {} finally { rs = null; }
        try { preStat.close(); } catch (Exception ignore) {} finally { preStat = null; }
      }
    }
  }
  
  /**
   * this function is to get record by memmber id and member type.
   * @param memberID
   * @param memberType
   * @return
   * @throws ApplicationException
   */
  public synchronized List getByMemberIDDocumentID(Integer memberID,String memberType) throws ApplicationException {
    return this.getByMemberIDDocumentID(memberID,memberType,null);
  }
  
 /**
  * Gets list of DmsObjectHomeFolder objects by member id, member type and document id
  * 
  * @param memberID member id
  * @param memberType member type include {@link com.dcivision.dms.bean.DmsObjectHomeFolder#MEMBER_TYPE_GROUP},
  *									      {@link com.dcivision.dms.bean.DmsObjectHomeFolder#MEMBER_TYPE_ROLE},
  *										  {@link com.dcivision.dms.bean.DmsObjectHomeFolder#MEMEBER_TYPE_USER}
  * @param documentID the document ID
  * @return list of DmsObjectHomeFolder objects
  * @throws ApplicationException
  */
  public synchronized List getByMemberIDDocumentID(Integer memberID,String memberType,Integer documentID) throws ApplicationException {
    PreparedStatement preStat = null;
    ResultSet rs = null;
    StringBuffer sqlStat = new StringBuffer();
    List result = new ArrayList();

    synchronized(dbConn) {
      try {
        sqlStat.append("SELECT A.ID, A.DOCUMENT_ID, A.MEMBER_ID, A.MEMBER_TYPE, A.ITEM_STATUS, A.RECORD_STATUS, A.UPDATE_COUNT, A.CREATOR_ID, A.CREATE_DATE, A.UPDATER_ID, A.UPDATE_DATE ");
        sqlStat.append("FROM   DMS_OBJECT_HOME_FOLDER A ");
        sqlStat.append("WHERE  A.RECORD_STATUS = ? ");
        sqlStat.append("AND A.MEMBER_ID=? AND A.MEMBER_TYPE=? ");
        if(!Utility.isEmpty(documentID)){
          sqlStat.append("AND A.DOCUMENT_ID=? ");
        }
        preStat = dbConn.prepareStatement(sqlStat.toString(), ResultSet.TYPE_SCROLL_INSENSITIVE, ResultSet.CONCUR_READ_ONLY);
        this.setPrepareStatement(preStat, 1, GlobalConstant.RECORD_STATUS_ACTIVE);
        this.setPrepareStatement(preStat, 2, memberID);
        this.setPrepareStatement(preStat, 3, memberType);
        if(!Utility.isEmpty(documentID)){
          this.setPrepareStatement(preStat, 4, documentID);     
        }
        
        rs = preStat.executeQuery();
        while (rs.next()) {
          DmsObjectHomeFolder tmpDmsObjectHomeFolder = new DmsObjectHomeFolder();
          tmpDmsObjectHomeFolder.setID(getResultSetInteger(rs, "ID"));
          tmpDmsObjectHomeFolder.setDocumentID(getResultSetInteger(rs, "DOCUMENT_ID"));
          tmpDmsObjectHomeFolder.setMemberID(getResultSetInteger(rs, "MEMBER_ID"));
          tmpDmsObjectHomeFolder.setMemberType(getResultSetString(rs, "MEMBER_TYPE"));
          tmpDmsObjectHomeFolder.setItemStatus(getResultSetString(rs, "ITEM_STATUS"));
          tmpDmsObjectHomeFolder.setRecordStatus(getResultSetString(rs, "RECORD_STATUS"));
          tmpDmsObjectHomeFolder.setUpdateCount(getResultSetInteger(rs, "UPDATE_COUNT"));
          tmpDmsObjectHomeFolder.setCreatorID(getResultSetInteger(rs, "CREATOR_ID"));
          tmpDmsObjectHomeFolder.setCreateDate(getResultSetTimestamp(rs, "CREATE_DATE"));
          tmpDmsObjectHomeFolder.setUpdaterID(getResultSetInteger(rs, "UPDATER_ID"));
          tmpDmsObjectHomeFolder.setUpdateDate(getResultSetTimestamp(rs, "UPDATE_DATE"));
          tmpDmsObjectHomeFolder.setCreatorName(UserInfoFactory.getUserFullName(tmpDmsObjectHomeFolder.getCreatorID()));
          tmpDmsObjectHomeFolder.setUpdaterName(UserInfoFactory.getUserFullName(tmpDmsObjectHomeFolder.getUpdaterID()));
          result.add(tmpDmsObjectHomeFolder);
        }
        return result;
      } catch (ApplicationException appEx) {
        throw appEx;
      } catch (SQLException sqle) {
        log.error(sqle, sqle);
        throw new ApplicationException(ErrorConstant.DB_GENERAL_ERROR, sqle, sqle.toString());
      } catch (Exception e) {
        log.error(e, e);
        throw new ApplicationException(ErrorConstant.DB_SELECT_ERROR, e);
      } finally {
        try { rs.close(); } catch (Exception ignore) {} finally { rs = null; }
        try { preStat.close(); } catch (Exception ignore) {} finally { preStat = null; }
      }
    }
  }
  
   /**
    * Gets the document (Folder) ID by member id and type
    * 
    * @param memberType member type include {@link com.dcivision.dms.bean.DmsObjectHomeFolder#MEMBER_TYPE_GROUP},
    *									    {@link com.dcivision.dms.bean.DmsObjectHomeFolder#MEMBER_TYPE_ROLE},
    *										{@link com.dcivision.dms.bean.DmsObjectHomeFolder#MEMEBER_TYPE_USER}
    * @param memberID the member id
    * @return the document ID
    * @throws ApplicationException
    */
   public synchronized Integer getDocIDByMemberIDType(String memberType,Integer memberID) throws ApplicationException {
     PreparedStatement preStat = null;
     ResultSet rs = null;
     StringBuffer sqlStat = new StringBuffer();
     List result = new ArrayList();
     Integer documentID = null;

     synchronized(dbConn) {
       try {
         sqlStat.append("SELECT A.DOCUMENT_ID ");
         sqlStat.append("FROM   DMS_OBJECT_HOME_FOLDER A ");
         sqlStat.append("WHERE  A.RECORD_STATUS = ? ");
         sqlStat.append("AND A.MEMBER_ID=? AND A.MEMBER_TYPE=?");
         preStat = dbConn.prepareStatement(sqlStat.toString(), ResultSet.TYPE_SCROLL_INSENSITIVE, ResultSet.CONCUR_READ_ONLY);
         this.setPrepareStatement(preStat, 1, GlobalConstant.RECORD_STATUS_ACTIVE);
         this.setPrepareStatement(preStat, 2, memberID);
         this.setPrepareStatement(preStat, 3, memberType);  
        
         rs = preStat.executeQuery();
         if(rs.next()) { 
           documentID = getResultSetInteger(rs, "DOCUMENT_ID");
         }
         return documentID;
       } catch (ApplicationException appEx) {
         throw appEx;
       } catch (SQLException sqle) {
         log.error(sqle, sqle);
         throw new ApplicationException(ErrorConstant.DB_GENERAL_ERROR, sqle, sqle.toString());
       } catch (Exception e) {
         log.error(e, e);
         throw new ApplicationException(ErrorConstant.DB_SELECT_ERROR, e);
       } finally {
         try { rs.close(); } catch (Exception ignore) {} finally { rs = null; }
         try { preStat.close(); } catch (Exception ignore) {} finally { preStat = null; }
       }
     }
   }
  
 /**
  * Gets list of the DmsObjectHomeFolder by the document ID.
  * 
  * @param documentID
  * @return list of dmsobjectHomeFolder objects
  * @throws ApplicationException
  */
  public synchronized List getListByDocumentID(Integer documentID) throws ApplicationException {
      PreparedStatement preStat = null;
      ResultSet rs = null;
      StringBuffer sqlStat = new StringBuffer();
      List result = new ArrayList();

      synchronized(dbConn) {
        try {
          sqlStat.append("SELECT A.ID, A.DOCUMENT_ID, A.MEMBER_ID, A.MEMBER_TYPE, A.ITEM_STATUS, A.RECORD_STATUS, A.UPDATE_COUNT, A.CREATOR_ID, A.CREATE_DATE, A.UPDATER_ID, A.UPDATE_DATE ");
          sqlStat.append("FROM   DMS_OBJECT_HOME_FOLDER A ");
          sqlStat.append("WHERE  A.RECORD_STATUS = ? ");
          sqlStat.append("AND A.DOCUMENT_ID = ? ");

          preStat = dbConn.prepareStatement(sqlStat.toString(), ResultSet.TYPE_SCROLL_INSENSITIVE, ResultSet.CONCUR_READ_ONLY);
          this.setPrepareStatement(preStat, 1, GlobalConstant.RECORD_STATUS_ACTIVE);
          this.setPrepareStatement(preStat, 2, documentID);
          
          rs = preStat.executeQuery();
          while (rs.next()) {
            DmsObjectHomeFolder tmpDmsObjectHomeFolder = new DmsObjectHomeFolder();
            tmpDmsObjectHomeFolder.setID(getResultSetInteger(rs, "ID"));
            tmpDmsObjectHomeFolder.setDocumentID(getResultSetInteger(rs, "DOCUMENT_ID"));
            tmpDmsObjectHomeFolder.setMemberID(getResultSetInteger(rs, "MEMBER_ID"));
            tmpDmsObjectHomeFolder.setMemberType(getResultSetString(rs, "MEMBER_TYPE"));
            tmpDmsObjectHomeFolder.setItemStatus(getResultSetString(rs, "ITEM_STATUS"));
            tmpDmsObjectHomeFolder.setRecordStatus(getResultSetString(rs, "RECORD_STATUS"));
            tmpDmsObjectHomeFolder.setUpdateCount(getResultSetInteger(rs, "UPDATE_COUNT"));
            tmpDmsObjectHomeFolder.setCreatorID(getResultSetInteger(rs, "CREATOR_ID"));
            tmpDmsObjectHomeFolder.setCreateDate(getResultSetTimestamp(rs, "CREATE_DATE"));
            tmpDmsObjectHomeFolder.setUpdaterID(getResultSetInteger(rs, "UPDATER_ID"));
            tmpDmsObjectHomeFolder.setUpdateDate(getResultSetTimestamp(rs, "UPDATE_DATE"));
            tmpDmsObjectHomeFolder.setCreatorName(UserInfoFactory.getUserFullName(tmpDmsObjectHomeFolder.getCreatorID()));
            tmpDmsObjectHomeFolder.setUpdaterName(UserInfoFactory.getUserFullName(tmpDmsObjectHomeFolder.getUpdaterID()));
            result.add(tmpDmsObjectHomeFolder);
          }
          return(result);
        } catch (ApplicationException appEx) {
          throw appEx;
        } catch (SQLException sqle) {
          log.error(sqle, sqle);
          throw new ApplicationException(ErrorConstant.DB_GENERAL_ERROR, sqle, sqle.toString());
        } catch (Exception e) {
          log.error(e, e);
          throw new ApplicationException(ErrorConstant.DB_SELECT_ERROR, e);
        } finally {
          try { rs.close(); } catch (Exception ignore) {} finally { rs = null; }
          try { preStat.close(); } catch (Exception ignore) {} finally { preStat = null; }
        }
      }
    }
  
  /**
   * Gets list of inactive dmsObjectHomeFolder objects by document ID
   * 
   * @param documentID
   * @return list of inactive dmsObjectHomeFolder objects
   * @throws ApplicationException
   */
  public synchronized List getInactiveListByDocumentID(Integer documentID) throws ApplicationException {
    PreparedStatement preStat = null;
    ResultSet rs = null;
    StringBuffer sqlStat = new StringBuffer();
    List result = new ArrayList();

    synchronized(dbConn) {
      try {
        sqlStat.append("SELECT A.ID, A.DOCUMENT_ID, A.MEMBER_ID, A.MEMBER_TYPE, A.ITEM_STATUS, A.RECORD_STATUS, A.UPDATE_COUNT, A.CREATOR_ID, A.CREATE_DATE, A.UPDATER_ID, A.UPDATE_DATE ");
        sqlStat.append("FROM   DMS_OBJECT_HOME_FOLDER A ");
        sqlStat.append("WHERE  A.RECORD_STATUS = ? ");
        sqlStat.append("AND A.DOCUMENT_ID = ? ");

        preStat = dbConn.prepareStatement(sqlStat.toString(), ResultSet.TYPE_SCROLL_INSENSITIVE, ResultSet.CONCUR_READ_ONLY);
        this.setPrepareStatement(preStat, 1, GlobalConstant.RECORD_STATUS_INACTIVE);
        this.setPrepareStatement(preStat, 2, documentID);
          
        rs = preStat.executeQuery();
        while (rs.next()) {
          DmsObjectHomeFolder tmpDmsObjectHomeFolder = new DmsObjectHomeFolder();
          tmpDmsObjectHomeFolder.setID(getResultSetInteger(rs, "ID"));
          tmpDmsObjectHomeFolder.setDocumentID(getResultSetInteger(rs, "DOCUMENT_ID"));
          tmpDmsObjectHomeFolder.setMemberID(getResultSetInteger(rs, "MEMBER_ID"));
          tmpDmsObjectHomeFolder.setMemberType(getResultSetString(rs, "MEMBER_TYPE"));
          tmpDmsObjectHomeFolder.setItemStatus(getResultSetString(rs, "ITEM_STATUS"));
          tmpDmsObjectHomeFolder.setRecordStatus(getResultSetString(rs, "RECORD_STATUS"));
          tmpDmsObjectHomeFolder.setUpdateCount(getResultSetInteger(rs, "UPDATE_COUNT"));
          tmpDmsObjectHomeFolder.setCreatorID(getResultSetInteger(rs, "CREATOR_ID"));
          tmpDmsObjectHomeFolder.setCreateDate(getResultSetTimestamp(rs, "CREATE_DATE"));
          tmpDmsObjectHomeFolder.setUpdaterID(getResultSetInteger(rs, "UPDATER_ID"));
          tmpDmsObjectHomeFolder.setUpdateDate(getResultSetTimestamp(rs, "UPDATE_DATE"));
          tmpDmsObjectHomeFolder.setCreatorName(UserInfoFactory.getUserFullName(tmpDmsObjectHomeFolder.getCreatorID()));
          tmpDmsObjectHomeFolder.setUpdaterName(UserInfoFactory.getUserFullName(tmpDmsObjectHomeFolder.getUpdaterID()));
          result.add(tmpDmsObjectHomeFolder);
        }
        return(result);
      } catch (ApplicationException appEx) {
        throw appEx;
      } catch (SQLException sqle) {
        log.error(sqle, sqle);
        throw new ApplicationException(ErrorConstant.DB_GENERAL_ERROR, sqle, sqle.toString());
      } catch (Exception e) {
        log.error(e, e);
        throw new ApplicationException(ErrorConstant.DB_SELECT_ERROR, e);
      } finally {
        try { rs.close(); } catch (Exception ignore) {} finally { rs = null; }
        try { preStat.close(); } catch (Exception ignore) {} finally { preStat = null; }
      }
    }
  }
  
  /**
   * Update the table 'DMS_OBJECT_HOME_FOLDER' Record by dmsObjectHomeFolder object.
   * 
   * @param dmsObjectHomeFolder the dmsObjectHomeFolder object
   * @return updated abstract object of dmsObjectHomeFolder
   * @throws ApplicationException
   */
  public synchronized AbstractBaseObject updateObjectHomeFolder(DmsObjectHomeFolder dmsObjectHomeFolder) throws ApplicationException {
     PreparedStatement preStat = null;
     StringBuffer sqlStat = new StringBuffer();
     
     synchronized(dbConn) {
       try {
         int updateCnt = 0;
         Timestamp currTime = Utility.getCurrentTimestamp();
         sqlStat.append("UPDATE DMS_OBJECT_HOME_FOLDER ");
         sqlStat.append("SET  DOCUMENT_ID=?, MEMBER_ID=?, MEMBER_TYPE=?, ITEM_STATUS=?, UPDATE_COUNT=?, UPDATER_ID=?, UPDATE_DATE=? , RECORD_STATUS=? ");
         sqlStat.append("WHERE  ID=? ");
         preStat = dbConn.prepareStatement(sqlStat.toString(), ResultSet.TYPE_SCROLL_INSENSITIVE, ResultSet.CONCUR_READ_ONLY);
         setPrepareStatement(preStat, 1, dmsObjectHomeFolder.getDocumentID());
         setPrepareStatement(preStat, 2, dmsObjectHomeFolder.getMemberID());
         setPrepareStatement(preStat, 3, dmsObjectHomeFolder.getMemberType());
         setPrepareStatement(preStat, 4, dmsObjectHomeFolder.getItemStatus());
         setPrepareStatement(preStat, 5, new Integer(dmsObjectHomeFolder.getUpdateCount().intValue() + 1));
         setPrepareStatement(preStat, 6, sessionContainer.getUserRecordID());
         setPrepareStatement(preStat, 7, currTime);
         setPrepareStatement(preStat,8,dmsObjectHomeFolder.getRecordStatus());
         setPrepareStatement(preStat, 9, dmsObjectHomeFolder.getID());
        
         updateCnt = preStat.executeUpdate();
         if (updateCnt == 0) {
           throw new ApplicationException(ErrorConstant.DB_CONCURRENT_ERROR);
         } else {
           dmsObjectHomeFolder.setUpdaterID(sessionContainer.getUserRecordID());
           dmsObjectHomeFolder.setUpdateDate(currTime);
           dmsObjectHomeFolder.setUpdateCount(new Integer(dmsObjectHomeFolder.getUpdateCount().intValue() + 1));
           dmsObjectHomeFolder.setCreatorName(UserInfoFactory.getUserFullName(dmsObjectHomeFolder.getCreatorID()));
           dmsObjectHomeFolder.setUpdaterName(UserInfoFactory.getUserFullName(dmsObjectHomeFolder.getUpdaterID()));
           return(dmsObjectHomeFolder);
         }
       } catch (ApplicationException appEx) {
         throw appEx;
       } catch (SQLException sqle) {
         log.error(sqle, sqle);
         throw new ApplicationException(ErrorConstant.DB_GENERAL_ERROR, sqle, sqle.toString());
       } catch (Exception e) {
         log.error(e, e);
         throw new ApplicationException(ErrorConstant.DB_UPDATE_ERROR, e);
       } finally {
         try { preStat.close(); } catch (Exception ignore) {} finally { preStat = null; }
       }
     }
   }
  
  
  /**
   * Delete the table 'DMS_OBJECT_HOME_FOLDER' Record by ID provided
   * 
   * @param ID the dmsDocument Object ID
   * @throws ApplicationException
   */
  public synchronized void deleteByID(Integer ID) throws ApplicationException {
     PreparedStatement preStat = null;
     StringBuffer sqlStat = new StringBuffer();
    
     synchronized(dbConn) {
       try {
         int updateCnt = 0;
         sqlStat.append("DELETE ");
         sqlStat.append("FROM   DMS_OBJECT_HOME_FOLDER ");
         sqlStat.append("WHERE  ID=?  ");
         preStat = dbConn.prepareStatement(sqlStat.toString(), ResultSet.TYPE_SCROLL_INSENSITIVE, ResultSet.CONCUR_READ_ONLY);
         setPrepareStatement(preStat, 1, ID);
        
         updateCnt = preStat.executeUpdate();
         if (updateCnt == 0) {
           throw new ApplicationException(ErrorConstant.DB_CONCURRENT_ERROR);
         } 
       } catch (ApplicationException appEx) {
         throw appEx;
       } catch (SQLException sqle) {
         log.error(sqle, sqle);
         throw new ApplicationException(ErrorConstant.DB_GENERAL_ERROR, sqle, sqle.toString());
       } catch (Exception e) {
         log.error(e, e);
         throw new ApplicationException(ErrorConstant.DB_DELETE_ERROR, e);
       } finally {
         try { preStat.close(); } catch (Exception ignore) {} finally { preStat = null; }
       }
     }
   }
  
  /**
   * Delete the table 'DMS_OBJECT_HOME_FOLDER' Record by member ID and member type
   * If system is soft delete enable, then update the deleted record is marked "Delete", the 
   * record status is inactive. Otherwise, delete the table record.
   * 
   * @param memberID
   * @param memberType
   * @throws ApplicationException
   */
  public synchronized void deleteByMemberIDMemberType(Integer memberID,String memberType) throws ApplicationException{
    PreparedStatement preStat = null;
    StringBuffer sqlStat = new StringBuffer();
   
    synchronized(dbConn) {
      try {
        int updateCnt = 0;
        boolean isSoftDeleteEnabled = new Boolean(SystemParameterFactory.getSystemParameter(SystemParameterConstant.SOFT_DELETE_ENABLE)).booleanValue();
        if(isSoftDeleteEnabled){
          sqlStat.append("UPDATE DMS_OBJECT_HOME_FOLDER ");
          sqlStat.append("SET RECORD_STATUS = 'I' ");
        }else{
          sqlStat.append("DELETE ");
          sqlStat.append("FROM   DMS_OBJECT_HOME_FOLDER ");
          
        }
        sqlStat.append("WHERE  MEMBER_ID = ? AND MEMBER_TYPE = ? ");
        preStat = dbConn.prepareStatement(sqlStat.toString(), ResultSet.TYPE_SCROLL_INSENSITIVE, ResultSet.CONCUR_READ_ONLY);
        setPrepareStatement(preStat, 1, memberID);
        setPrepareStatement(preStat, 2, memberType);
        updateCnt = preStat.executeUpdate();
      } catch (SQLException sqle) {
        log.error(sqle, sqle);
        throw new ApplicationException(ErrorConstant.DB_GENERAL_ERROR, sqle, sqle.toString());
      } catch (Exception e) {
        log.error(e, e);
        throw new ApplicationException(ErrorConstant.DB_DELETE_ERROR, e);
      } finally {
        try { preStat.close(); } catch (Exception ignore) {} finally { preStat = null; }
      }
    }
  }
  
  public synchronized void updateRecordStatusByDocumentIDList(List documentIds, String recordStatus) throws ApplicationException {
    PreparedStatement preStat = null;
    StringBuffer sqlStat = new StringBuffer();
    synchronized(dbConn) {
      try {
        sqlStat.append("UPDATE DMS_OBJECT_HOME_FOLDER ");
        sqlStat.append("SET RECORD_STATUS=? ");
        sqlStat.append("WHERE  DOCUMENT_ID IN (");
        for (int i=0; i<documentIds.size(); i++) {
          sqlStat.append(i!=0?",?":"?");
        }
        sqlStat.append(") ");
        preStat = dbConn.prepareStatement(sqlStat.toString(), ResultSet.TYPE_SCROLL_INSENSITIVE, ResultSet.CONCUR_READ_ONLY);
        int counter = 1;
        this.setPrepareStatement(preStat, counter++, recordStatus);
        for (int i=0; i<documentIds.size(); i++) {
          this.setPrepareStatement(preStat, counter++, (Integer)documentIds.get(i));
        }
        preStat.executeUpdate();
      } catch (SQLException sqle) {
        log.error(sqle, sqle);
        throw new ApplicationException(ErrorConstant.DB_GENERAL_ERROR, sqle, sqle.toString());
      } catch (Exception e) {
        log.error(e, e);
        throw new ApplicationException(ErrorConstant.DB_UPDATE_ERROR, e);
      } finally {
        try { preStat.close(); } catch (Exception ignore) {} finally { preStat = null; }
      }
    }
  }
  
}
